home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Melt the Control Strip / source code / layermgr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  4.8 KB  |  128 lines  |  [TEXT/ttxt]

  1. /*
  2. [Moderator's note:  Apple has officially stated that these calls
  3.  are undocumented for a reason: THEY ARE NOT TO BE USED!  They
  4.  have also said that any software using the Layer Manager will break
  5.  within a year (of 1/94).  I am still including the file in the
  6.  archive however.  But you have been warned!!! - dn]
  7.  
  8.  
  9. From: hugues@isoftfr.isoft.fr (Hugues Marty)
  10. Subject: UNofficial description of 2 Layer Manager calls
  11.  
  12. This post contains a header and an example of how to use some calls of
  13. the UNDOCUMENTED (as long as I know) Layer Manager which comes along
  14. with System 7.  Of course, this is NOT an official document, and is
  15. here for information only. I don't have News access at the moment (I'm
  16. sending this via e-mail), so please send mail me copies if you post
  17. follow-ups.
  18.  
  19. PS: it only describes 2 calls of the LayerDispatch trap (0xA829).
  20. PPS: seems to work under 7.1 beta.
  21.  
  22. - ---- C #include file following
  23. */
  24.  
  25. /* Layers.h */
  26.  
  27. /* Part of the undocumented Layer Manager structures and calls
  28.  * Information found with the help of MacsBug under MacOS 7.0.
  29.  * Please note that using this information may make your mac
  30.  * explode (hey, this could be a subject for a QuickTime moovie !);
  31.  * so use at your own risks, this may break in the future,
  32.  * etc.. (usual disclaimeer).
  33.  * I only wish that Apple will document this manager in a very near
  34.  * future (let's dream...).
  35.  *
  36.  * What I found was that a layer is associated with each running
  37.  * applications (if it has a user-interface), which groups all
  38.  * windows of that application. This is how you can hide an application
  39.  * (remember 'applications' menu under system 7) and get the list of
  40.  * other applications windows. Have fun.
  41.  *
  42.  * PS : If you have more information on the Layer Manager, please
  43.  * let me know! You can join me at hugues@isoft.fr
  44.  */
  45.  
  46. /*#include <PasStrs.h>*/
  47.  
  48. // LayerRecord is similar to a WindowRecord.
  49. typedef WindowRecord LayerRecord;
  50. typedef WindowPeek LayerPtr;
  51.  
  52. // This records some information on the process which owns
  53. // the layer... Most of it is not clear (there are pointers
  54. // to other LayerRecords, to a heap zone, etc. in the unknown
  55. // parts)
  56. typedef struct {
  57.    long unknown1;
  58.    OSType    signature;           // The process sig.
  59.    OSType    creator;             // The process creator
  60.    char      unknown2[24];
  61.    ProcessSerialNumber layerPSN;  // The process PSN
  62.    char      unknown3[40];
  63.    Handle    moreLayerInfo;       // This handle is 212 bytes sized.
  64. } LayerInfo, *LayerInfoPtr;
  65.  
  66. // This function returns a pointer to the first layer record
  67. // of the front layer on screen (front application).
  68. // Other ones are then accessed by the GetNextLayer macro.
  69. pascal LayerPtr GetFirstLayer(void)
  70.     = {0x7003, 0xA829};
  71.  
  72. // This function returns a pointer to the first window record
  73. // in the windows list of this layer.
  74. pascal WindowPtr GetFirstLayerWindow(LayerPtr aLayer)
  75.     = {0x7006, 0xa829};
  76.  
  77. // Some macros to access other information, and to hide and show a layer
  78. #define GetNextLayer(aLayer) (aLayer->nextWindow)
  79. #define GetLayerInfo(aLayer) ((LayerInfoPtr)aLayer->refCon)
  80. #define HideLayer(aLayer) HideWindow((WindowPtr)aLayer)
  81. #define ShowLayer(aLayer) ShowWindow((WindowPtr)aLayer)
  82. #define ShowHideLayer(aLayer,showFlag) ShowHide((WindowPtr)aLayer, showFlag)
  83. #define HiddenLayer(aLayer) aLayer->visible
  84.  
  85. // GetLayerName will return an address in a handle. Be aware of that.
  86. #define GetLayerName(aLayer) \
  87. (unsigned char *) ( (*GetLayerInfo(aLayer)->moreLayerInfo) + 0x38)
  88.  
  89.  
  90. /** Some sample code to show how to put the list of layers and their
  91.  ** windows names in a styled text with TextEdit.
  92.  **
  93.  
  94.         TEHandle hTE;
  95.         LayerPtr theLayer;
  96.         Str255 name;
  97.         TextStyle style;
  98.         WindowPeek window;
  99.         LayerInfoPtr info;
  100.         
  101.         hTE = TEStylNew(&windowRect, &windowRect);
  102.         theLayer = GetFirstLayer();
  103.         do {
  104.                 style.tsFace = bold;
  105.                 TESetStyle(doFace, &style, false, hTE);
  106.                 Pstrcpy(name, GetLayerName(theLayer));
  107.                 TEInsert(name+1, name[0], hTE);
  108.                 TEInsert("\015", 1, hTE);
  109.                 style.tsFace = 0;
  110.                 TESetStyle(doFace, &style, false, hTE);
  111.                 window = (WindowPeek) GetFirstLayerWindow(theLayer);
  112.                 while(window) {
  113.                         if (StripAddress(window->titleHandle) && StripAddress(*
  114. window->titleHandle)) {
  115.                                 Pstrcpy(name, *window->titleHandle);
  116.                                 TEInsert(name+1, name[0], hTE);
  117.                                 TEInsert("\015", 1, hTE);
  118.                         }
  119.                         window = window->nextWindow;
  120.                 }
  121.         } while (theLayer = GetNextLayer(theLayer));
  122.  
  123. **  The End */
  124. /*- --
  125. Hugues MARTY - ISoft, Chemin de Moulon, F-91190 Gif-sur-Yvette FRANCE
  126. e-mail: hugues@isoft.fr*/
  127.  
  128.